﻿#region Using

using Vk.Methods.Common.AttachmentTypes;

#endregion

namespace Vk.Methods.Common
{
    /// <summary>
    /// Базовая информация о вложении
    /// </summary>
    /// <typeparam name="TTypeEnum">Перечисление с доступными типами вложений</typeparam>
    public abstract class AttachmentBase<TTypeEnum> where TTypeEnum : struct
    {
        /// <summary>
        ///     Строковое представление вложения
        /// </summary>
        public string AttachmentString { get; set; }

        /// <summary>
        ///     Информация о вложении
        /// </summary>
        public AttachmentData Data { get; set; }

        /// <summary>
        ///     Тип вложения
        /// </summary>
        public TTypeEnum? Type { get; set; }

        public AttachmentBase(ApiNode node)
        {
            AttachmentString = node.String();
            Type = node.Enum<TTypeEnum>("type");
        }
    }

    /// <summary>
    ///     Медиавложение на стене
    /// </summary>
    public class WallAttachment : AttachmentBase<WallAttachmentType>
    {
        public WallAttachment(ApiNode node) : base(node)
        {
            var attachmentData = node.SelectNode(node.String("type"));
            Data = attachmentData != null ? Attachments.GetAttachment(Type.Value, attachmentData) : null;
        }
    }

    /// <summary>
    ///     Медиавложение в ЛС
    /// </summary>
    public class MessageAttachment : AttachmentBase<MessageAttachmentType>
    {
        public MessageAttachment(ApiNode node) : base(node)
        {
            var attachmentData = node.SelectNode(node.String("type"));
            Data = attachmentData != null ? Attachments.GetAttachment(Type.Value, attachmentData) : null;
        }
    }
}